#include("./common/header.html", {site_title:"发布新帖子"})
<link rel="stylesheet" href="${base}/assets/lib/highlight/styles/default.css"/>
<link rel="stylesheet" href="${base}/assets/lib/highlight/styles/github.css"/>
<script src="${base}/assets/lib/highlight/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<div class="container">
    <div class="row">
        <div class="col-md-9">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">发布新帖子</h3>
                </div>
                <div class="panel-body">
                    <form id="topic-add" role="form" onsubmit="return publish_topic();">
                        <div class="form-group">
                            <label for="title">标题</label>
                            <input type="text" class="form-control" id="title" name="title" placeholder="请输入帖子标题"
                                   required="required" aria-required="true"/>
                        </div>
                        <div class="form-group">
                            <label for="nid">节点</label>
                            <select class="form-control" id="nid" name="nid">
                                <option value="">请选择节点</option>
                                #for(node : nodes)
                                #if(node.pid == 0)
                                #if(null != node.items)
                                <optgroup label="${node.title}">
                                    #for(item : node.items)
                                    <option #if(null !=pid && pid== item.nid)selected="selected" #end
                                            value="${item.nid}">${item.title}
                                    </option>
                                    #end
                                    #else
                                    <option value="${node.nid}">${node.title}</option>
                                    #end
                                    #end
                                    #end
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="nid">帖子内容</label>
                            <div class="form-group">
	                            <textarea data-emojiable="true" id="content" class="form-control"
                                          placeholder="撸下你要发射的内容!!!" name="content" rows="8"
                                          required="required"></textarea>
                            </div>
                        </div>
                        <div>
                            <button type="button" class="btn btn-default btn-small preview">预览帖子</button>
                            <button type="submit" class="btn btn-primary btn-small" data-style="zoom-out">
                                <span class="ladda-label">发布帖子</span>
                            </button>
                        </div>
                    </form>
                </div>
                <div id="markdown_preview" class="panel-footer hide"></div>
            </div>
        </div><!-- /.col-md-8 -->
        #include("./common/sidebar.html")
    </div>
</div>
#include("./common/footer.html")
<script type="text/javascript">
    function publish_topic() {
        var title = $('#topic-add #title').val();
        var nid = $('#topic-add #nid').val();
        if (title == '') {
            jc.alertWarn('请输入帖子标题');
            return false;
        }
        if (nid == '') {
            jc.alertWarn('请选择一个节点');
            return false;
        }
        jc.post({
            url: '/topic/add',
            data: $('#topic-add').serialize(),
            success: function (result) {
                if (result && result.success) {
                    var tid = result.payload;
                    window.location.href = '/topic/' + tid;
                } else {
                    if (result.code == 401) {
                        go_signin();
                    } else {
                        jc.alertError(result.msg || '帖子发布失败');
                    }
                }
            }
        });
        return false;
    }
</script>
</body>
</html>